R HW3

library(maptools)
## 載入需要的套件:sp
## Warning: 套件 'sp' 是用 R 版本 4.1.2 來建造的
## Checking rgeos availability: TRUE
## Please note that 'maptools' will be retired by the end of 2023,
## plan transition at your earliest convenience;
## some functionality will be moved to 'sp'.
library(rgdal)
## Please note that rgdal will be retired by the end of 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## 
## rgdal: version: 1.5-27, (SVN revision 1148)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.2.1, released 2020/12/29
## Path to GDAL shared files: C:/Users/Dear User/Documents/R/win-library/4.1/rgdal/gdal
## GDAL binary built with GEOS: TRUE 
## Loaded PROJ runtime: Rel. 7.2.1, January 1st, 2021, [PJ_VERSION: 721]
## Path to PROJ shared files: C:/Users/Dear User/Documents/R/win-library/4.1/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:1.4-5
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
## Overwritten PROJ_LIB was C:/Users/Dear User/Documents/R/win-library/4.1/rgdal/proj
library (sp)
library(raster)
library(ggplot2)
library(sf)
## Warning: 套件 'sf' 是用 R 版本 4.1.2 來建造的
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1
library(rnaturalearth)
library(rnaturalearthdata)
library(ggspatial)
library(rgbif)
library(mapr)
library(marmap)
## Registered S3 methods overwritten by 'adehabitatMA':
##   method                       from
##   print.SpatialPixelsDataFrame sp  
##   print.SpatialPixels          sp
## 
## 載入套件:'marmap'
## 下列物件被遮斷自 'package:raster':
## 
##     as.raster
## 下列物件被遮斷自 'package:grDevices':
## 
##     as.raster
library(leaflet)


url <- 'https://data.moi.gov.tw/MoiOD/System/DownloadFile.aspx?DATA=72874C55-884D-4CEA-B7D6-F60B0BE85AB0'
path1 <- tempfile(fileext = ".zip")
if (file.exists(path1))  'file alredy exists' else download.file(url, path1, mode="wb")
unzip(zipfile = path1,exdir = 'Data')

taiwan <- readOGR('Data/COUNTY_MOI_1090820.shp', use_iconv=TRUE, encoding='UTF-8')
## Warning in OGRSpatialRef(dsn, layer, morphFromESRI = morphFromESRI, dumpSRS =
## dumpSRS, : Discarded datum Taiwan_Datum_1997 in Proj4 definition: +proj=longlat
## +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +no_defs
## OGR data source with driver: ESRI Shapefile 
## Source: "C:\Users\Dear User\Desktop\R-GITHUB\Rhomework3\Data\COUNTY_MOI_1090820.shp", layer: "COUNTY_MOI_1090820"
## with 22 features
## It has 4 fields
FRE <- paste(sep = "<br/>",
  "<b><a href='https://www.dipintothereef.com/'>406Lab TAIWAN</a></b>",
  "Reef Ecology and Microbiology Lab",
  "Institute of Fishery Science, NTU")


leaflet(taiwan) %>%
  addPolygons(weight=0.5) %>%
  addTiles(group="Kort") %>%
  addPopups(121.539418239001, 25.020888875540166, FRE, options = popupOptions(closeButton = FALSE))